# -*- coding: utf-8 -*-
import datetime
import time

from PageClass.boe_NewGeneralLedgerClass.Class_NewGeneralLedgerBoe import Class_NewGeneralLedgerBoe
from TestCases.common import LoginDepend
from TestCases.common._baseClass import _BaseClass
from Util import config, logger, record


class BoeSubmit(_BaseClass):

    def __init__(self, isExit=True):
        self.isExit = isExit
        self.login = LoginDepend('basHost', 'user')
        self.NewGeneralLedger = Class_NewGeneralLedgerBoe(self.login.driver)

    def __exit__(self, *args):
        if super().__exit__(*args):
            if self.isExit:
                self.exit()
        else:
            self.exit()

    def exit(self):
        self.NewGeneralLedger.driver.quit()

    def submit(self, boe_data):
        logger.info(f"业务报账地址为：{config.urlDict.url.basHost}")

        # 打开总账单填单界面
        self.NewGeneralLedger.open_boe(boe_data.boeType)

        # 获取单号
        boeNo = self.NewGeneralLedger.getBoeNum()
        record.writeDataToRecord({'boeNo': boeNo, 'boeType': boe_data.boeType})

        # 主表区-记账类型[优先选择]
        self.NewGeneralLedger.click_operationTypeId(boe_data.operationTypeId)
        # 主表区-总账记账日期
        self.NewGeneralLedger.select_gldate()
        # 凭证分录-'+'按钮,加一行
        self.NewGeneralLedger.clickAddByHandle()
        # 凭证分录-会计科目,第一行
        self.NewGeneralLedger.click_accountName(1, boe_data.account_code_1)
        # 凭证分录-会计科目,第二行
        self.NewGeneralLedger.click_accountName(2, boe_data.account_code_2)
        # 凭证分录-借方金额，第一行
        self.NewGeneralLedger.click_debitAmount(1, boe_data.money_1)
        # 凭证分录-贷方金额，第二行
        self.NewGeneralLedger.click_creditAmount(2, boe_data.money_1)
        # 提交单据
        message = self.NewGeneralLedger.click_boeSubmitButton()
        return message
